% Function that takes an input .wav file and outputs a delayed .wav with
% the given parameters
%
%Charles Cloud
%Team: Zach come back!

function[] = addDelayToSound(inSound, delayInSeconds, ampDelay)

%y is the array of bytes, Fs is the sampling frequency, bits is the bit rate
[soundArray,Fs,bits] = wavread(inSound);

%create a new array with enough space for our sound + the delay
%delay time * Fs should give us the amount of new space we need for our sample
timeShifted = zeros(1,length(soundArray)+(delayInSeconds*Fs));

%copy over original array to latter part of first array
%this will serve as the delayed part
startPos = (length(timeShifted)-length(soundArray)+1);
timeShifted(startPos:length(timeShifted)) = soundArray(1:length(soundArray));

%create another array to hold original with added 0's at the end
soundArray2 = zeros(1,length(timeShifted));
%copy it over
soundArray2(1:length(soundArray)) = soundArray(1:length(soundArray));

%add the two arrays together
%cut the amplitude of the second one by the amp delay
delayedSound = soundArray2 + (ampDelay*timeShifted);

%output the sound
nameString = 'delayedSound';
wavwrite(delayedSound,Fs,nameString);